#include"util.h"

XYZ normalizeVector(XYZ a)
{
	double length = sqrt(a.x*a.x + a.y*a.y + a.z*a.z);
	XYZ result;
	result.x = a.x/length;
	result.y = a.y/length;
	result.z = a.z/length;
	return result;
}

double calcVectorLen(XYZ a)
{
	double length = sqrt(a.x*a.x + a.y*a.y + a.z*a.z);
	return length;
}

double scalarMultiplication(XYZ a, XYZ b)
{
	return a.x*b.x + a.y*b.y + a.z*b.z;
}

double sqr(double a)
{
	return a*a;
}

double getSquare(XYZ p1, XYZ p2, XYZ p3)
{
	double a, b, c, p;
	a = sqrt(sqr(p2.x-p1.x) + sqr(p2.y-p1.y) + sqr(p2.z-p1.z));
	b = sqrt(sqr(p3.x-p2.x) + sqr(p3.y-p2.y) + sqr(p3.z-p2.z));
	c = sqrt(sqr(p1.x-p3.x) + sqr(p1.y-p3.y) + sqr(p1.z-p3.z));
	p = (a + b + c) / 2;

	return sqrt(p*(p-a)*(p-b)*(p-c));
}
